{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card">
	<div class="layui-card-body">
		<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-card layui-col-md12">
			<div class="layui-card-header">
				{if !$info['id']}<i class="fa fa-plus"></i> 添加秒杀{else}<i class="fa fa-pencil"></i> 编辑秒杀{/if}
				<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
			</div>
			<div class="layui-card-body" pad15>
				<div class="layui-form form-label-w6" lay-filter="">
					<input type="hidden" name="id" value="{$info['id']}">
					<div class="layui-form-item">
						<label class="layui-form-label">活动名称：</label>
						<div class="layui-input-inline">
							<input type="text" name="info[name]" value="{$info.name}" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">商品：</label>
						<input type="hidden" name="info[goods_id]" value="{$info['goods_id']}" />
						<div class="layui-btn layui-btn-primary" style="float:left" onclick="showChooseProduct()">选择商品</div>
					</div>

					<script>
						var cxtype = '{$info.type}';
						var chooseProductLayer;
						function showChooseProduct(){
							var url = "{:url('Goods/choosegoods')}/hidebid/1/editprice/1";
							chooseProductLayer = layer.open({type:2,title:'选择商品',content:url,area:['1000px','600px'],shadeClose:true});
						}
						function choosegoods(res){
							console.log(res);
							var html = '';
							var product_ids = [];
							// $(res_arr).each(function(i, res) {
								var product = res;
								product_ids.push(product.goods_id);
								var gglist = product.gglist;
								layer.close(chooseProductLayer);
								var gg_length = gglist.length;
								console.log(gglist.length);
								$(gglist).each(function (i, val) {
									console.log(val);
									console.log(val.name);
									html += '<tr>';
									if (i == 0) {
										html += '<td rowspan="' + gg_length + '">' + product.goods_name + '(ID:' + product.goods_id + ')</td>';
									}
									html += '<td>' + val.key_name + '</td>' +
											'<td>' + val.cost_price + '</td>' +
											'<td>' + val.shop_price + '</td>' +
											'<td><input type="text" class="layui-input" name="price[' + val.item_id + ']" value="' + val.shop_price + '" style="width:80px" /></td>' +
											'</tr>';
								});
							// })
							$('input[name="info[goods_id]"]').val(product_ids);
							$('#productaddtr').html(html);
						}
					</script>

					<div class="layui-form-item" id="setgg">
						<label class="layui-form-label">商品信息：</label>
						<div class="layui-input-inline" style="width:auto">
							<table id="ggnamediv"  class="layui-table" style="width:900px">
								<thead>
								<tr>
									<th style="width:400px">商品名称</th>
									<th>规格</th>
									<th>原成本价</th>
									<th>原销售价</th>
									<th>秒杀价</th>
								</tr>
								</thead>
								<tbody id="productaddtr">
								{if $product}
								{foreach $product['gglist'] as $k2=>$val}
								<tr>
									{if $k2==0}
									<td rowspan="{:count($product['gglist'])}">{$product.goods_name}(ID:{$product.goods_id})</td>
									{/if}
									<td>{$val.key_name}</td>
									<td>{$val.cost_price}</td>
									<td>{$val.shop_price}</td>
									<td><input type="text" class="layui-input" name="price[{$val['item_id']}]" value="{$product['price_arr'][$val['item_id']]}" style="width:80px" /></td>
								</tr>
								{/foreach}
								{else}
								<tr>
									<td colspan="6" style="text-align: center">请选择商品</td>
								</tr>
								{/if}
								</tbody>

							</table>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">秒杀库存：</label>
						<div class="layui-input-inline">
							<input type="text" name="info[stock]" value="{$info.stock}" class="layui-input">
						</div>
						<div class="layui-form-mid">件</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">秒杀时间：</label>
						<div class="layui-input-inline">
							<input type="text" name="info[stime]" value="{$info.stime}" class="layui-input" id="stime" placeholder="yyyy-MM-dd HH:mm:ss">
						</div>
						<div class="layui-form-mid">至</div>
						<div class="layui-input-inline">
							<input type="text" name="info[etime]" value="{$info.etime}" class="layui-input" id="etime" placeholder="yyyy-MM-dd HH:mm:ss">
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">状态：</label>
						<div class="layui-input-inline">
							<input type="radio" name="info[status]" value="0" title="关闭" {if $info['status']==0}checked{/if}>
							<input type="radio" name="info[status]" value="1" title="开启" {if !$info['id'] || $info['status']==1}checked{/if}>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"></label>
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit lay-filter="formsubmit">提 交</button>
						</div>
					</div>
		</div>
	</div>
</div>
</div>
</div>
	</div>
</div>
<script>
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
	layui.laydate.render({
		elem: '#stime',
		type: 'datetime',
		fullPanel: true // 2.8+
	});
	layui.laydate.render({
		elem: '#etime',
		type: 'datetime',
		fullPanel: true // 2.8+
	});
</script>
</body>
</html>